<?php
$html->addCrumb('Admin','/admin/roles');
$html->addCrumb('Rollen verwalten','/admin/roles/index');

echo  $this->element('tasks',array('target'=>'/admin/roles'));
				?>

<div class="title">Rollen verwalten</div>
<?php echo $this->element('flashMessage') ?>
<div>
	<div></div>
	<table>
		<tr>
			<th>Rollenname</th>
			<th>Beschreibung</th>
			<th class="noprint">Aktion</th>
			<th class="noprint">Status</th>
		</tr>
		<?php
		$out = '';
		foreach($this->data as $key => $value){
			$isAdmin = preg_match(REGEX_ADMIN_OR_OPERATOR,$value['Role']['role_name'],$matches)>0;
			//debug($matches);
			$out .='<tr>';
			$out .='<td>';
			$out .= $value['Role']['role_name'];
			$out .='</td>';
			$out .='<td>';
			$out .= $value['Role']['description'];
			$out .='</td>';
			$out .='<td class="noprint">';
			if(!$isAdmin){
				$out .=' <a href="'.URL_PREFIX.'/admin/roles/update/'.$value['Role']['id'].'"><button>Ändern</button></a>';
				if($value['State']['id']==1){
					$active = 2;
					$activeText = '<button>Aktiv</button>';
				}else{
					$active = 1;
					$activeText = '<button>IN-Aktiv</button>';
				}
				$out .='<a href="'.URL_PREFIX.'/admin/roles/delete/'.$value['Role']['id'].'"><button>Löschen</button></a>';
			}else{
				$out .= 'Keine Aktion';
			}
			$out .='</td>';
			$out .='<td class="noprint">';
			if(!$isAdmin){
				$out .='<a href="'.URL_PREFIX.'/admin/roles/setState/'.$value['Role']['id'].'/'.$active.'">'.$activeText.'</a>';
			}else{
				$out .= 'Aktiv';
			}
			$out .='</td>';
			$out .='</tr>';
		}
		echo $out;
		?>
	</table>
</div>
